home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / UP&DOWN.ASM < prev    next >
Assembly Source File  |  1996-08-26  |  5KB  |  222 lines

  1. ; UP&DOWN.ASM for E32 - Copyright (C) 1994 - 1996 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ; 08/26/1996 DH: added support for SCROLL LOCK
  5.  
  6. include    model.inc
  7.  
  8. public    up, down, screen_dn, screen_up
  9. extrn    find_cr:near
  10. extrn    find_start:near
  11. extrn    shift_right:near
  12. extrn    find_previous:near
  13. extrn    find_next:near
  14.  
  15. include    dataseg.inc
  16. extrn    undo_length:dword, cur_posn:word, cursor:dword
  17. extrn    top_of_screen:dword, dirty_bits:byte, rows:byte
  18. extrn    filesiz:dword, mark_mode:byte
  19. extrn    file_row:dword, saved_pos:word, first_row:byte
  20. extrn    display_mode:byte, key_status:byte
  21.  
  22. page_proc    dd 0            ; for PGUP, PGDN
  23.  
  24. up_proc        dd offset up_ascii
  25.         dd offset up_hex
  26. down_proc    dd offset down_ascii
  27.         dd offset down_hex
  28.  
  29. @curseg    ends
  30.  
  31. include    codeseg.inc
  32.  
  33. up    proc    near
  34.  
  35. ;
  36. ;   this moves the cursor up one row.  If the cursor is at the first
  37. ;   row, the screen is scrolled down.
  38. ;
  39.  
  40.     mov    dx,cur_posn
  41.     movzx    esi,display_mode
  42.     jmp    up_proc[esi]
  43.  
  44. up_hex:
  45.     mov    esi,cursor
  46.     sub    esi,10h
  47.     jnc    short save_cursor_hex
  48.     clc
  49.     ret
  50.  
  51. save_cursor_hex:
  52.     mov    cursor,esi
  53.     dec    dh
  54.     cmp    dh,first_row
  55.     jae    short exit_up_hex
  56.     inc    dh
  57.     mov    eax,top_of_screen
  58.     sub    eax,10h
  59.     jnc    short save_screen_top
  60.     xor    eax,eax
  61. save_screen_top:
  62.     mov    top_of_screen,eax
  63. exit_up_hex:
  64.     mov    cur_posn,dx
  65.     or    dirty_bits,1
  66.     ret
  67.  
  68. up_ascii:
  69.     push    es
  70.     mov    undo_length,0
  71.     push    fs
  72.     pop    es
  73.     mov    esi,cursor
  74.     dec    dh            ; move cursor up one row
  75.     cmp    dh,first_row
  76.     jb    short screen_dn        ; if at top row then scroll down
  77.     test    key_status,08h
  78.     jz    short ua0        ; move cursor on screen if SCROLL off
  79.     cmp    top_of_screen,0        ; top of screen already displayed?
  80.     jne    short screen_dn        ;  no, scroll the screen
  81. ua0:
  82.     dec    file_row
  83.     call    find_cr            ; find the beginning of this row
  84.     mov    cursor,esi
  85.     call    find_start        ; find start of this row
  86.     mov    cursor,esi
  87.     call    shift_right        ; skip over to current column
  88. at_top:    clc
  89.     pop    es
  90.     ret
  91.  
  92. screen_dn:
  93.     mov    esi,top_of_screen
  94.     or    esi,esi        ; at start of file?
  95.     jz    at_top        ; if at top then do nothing
  96.     mov    saved_pos,-1    ; refresh row, col on top line
  97.     push    fs
  98.     pop    es
  99.     call    find_previous    ; find the preceeding line
  100.     mov    top_of_screen,esi
  101.     dec    file_row
  102.     mov    esi,cursor
  103.     call    find_previous    ; find the preceeding line
  104.     mov    cursor,esi    ; this is the new cursor
  105. shift_ret:
  106.     or    dirty_bits,1    ; need to redraw screen
  107.     mov    esi,cursor
  108.     mov    dx,cur_posn
  109.     call    shift_right    ; move cursor to current column
  110. exit:    clc
  111.     pop    es
  112.     ret
  113. up    endp
  114.  
  115. down    proc    near
  116.  
  117. ;
  118. ; This moves the cursor down one row.  When the last
  119. ; row is reached, the screen is shifted up one row.
  120. ;
  121.     push    es
  122.     push    fs
  123.     pop    es
  124.     mov    dx,cur_posn
  125.     movzx    esi,display_mode
  126.     jmp    down_proc[esi]
  127.  
  128. down_hex:
  129.     mov    esi,cursor
  130.     add    esi,10h
  131.     cmp    esi,filesiz
  132.     jae    down_ret
  133.  
  134.     mov    cursor,esi
  135.     inc    dh
  136.     cmp    dh,rows
  137.     jbe    short down_hex1
  138.     add    top_of_screen,10h
  139.     jmp    short down_hex2
  140.  
  141. down_hex1:
  142.     mov    cur_posn,dx
  143.  
  144. down_hex2:
  145.     or    dirty_bits,1
  146.     pop    es
  147.     ret
  148.  
  149. ;
  150. ; file displayed in ASCII mode
  151. ;
  152. down_ascii:
  153.     mov    undo_length,0
  154.     cmp    dh,rows        ; at bottom row already?
  155.     mov    esi,cursor    ; get position in file
  156.     jae    short screen_up    ; if at bottom, scroll up
  157.     test    key_status,08h    ; SCROLL LOCK on?
  158.     jnz    short screen_up    ;  move scren if so
  159.     call    find_next    ; find the start of the next line
  160.     jc    short down_ret    ; if no more lines, then return
  161.     mov    cursor,esi
  162.     inc    dh        ; advance cursor to next row
  163.     inc    file_row
  164.     call    shift_right    ; move cursor to next column
  165. down_ret:
  166.     clc
  167.     pop    es
  168.     ret
  169.  
  170. screen_up:
  171.     mov    esi,cursor    ; get position in file
  172.     cmp    esi,filesiz    ; get cursor offset
  173.     je    down_ret
  174.     mov    saved_pos,-1    ; refresh row, col on top line
  175.     push    fs
  176.     pop    es
  177.     call    find_start    ; find the start of this line
  178.     mov    cursor,esi    ; this is the new cursor
  179.     call    find_next    ; find the offset of next line
  180.     jc    shift_ret    ; if no more lines the return
  181.     inc    file_row
  182.     mov    cursor,esi    ; this is the new cursor
  183.     mov    esi,top_of_screen    ; get the start of the top row
  184.     call    find_next    ; and find the next line
  185.     mov    top_of_screen,esi    ; store the new top of screen
  186.     jmp    shift_ret
  187. down    endp
  188.  
  189. @curseg    ends
  190.  
  191.  
  192. ; PGUP, PGDN
  193. ;
  194. ; These two routines move the screen one page at
  195. ; a time by calling the UP and DOWN procedures.
  196.  
  197. public    pgdn, pgup
  198.  
  199. include    codeseg.inc
  200. pgdn    proc    near
  201.     mov    page_proc,offset down
  202. page_up_dn:
  203.     movzx    ecx,rows    ; get the length of the screen
  204.     sub    cl,4        ; don't page a full screen
  205.     sub    cl,first_row
  206. page_loop:
  207.     push    ecx
  208.     call    page_proc    ; move the cursor down
  209.     pop    ecx
  210.     loop    page_loop
  211.     clc
  212.     ret
  213. pgdn    endp
  214.  
  215. pgup    proc    near
  216.     mov    page_proc,offset up
  217.     jmp    page_up_dn
  218. pgup    endp
  219.  
  220. @curseg    ends
  221.     end
  222.